package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ProductBean;
import com.project.mapper.IProductMapper;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class ProductServiceImpl implements IProductService {

    @Autowired
    private IProductMapper mapper;


    @Override
    public ProductBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public PageInfo<ProductBean> findByItem(int pageNo, String name, LocalDate startDate, LocalDate endDate,String status) {
        PageHelper.startPage(pageNo,3);
        PageInfo<ProductBean>pageInfo=PageInfo.of(mapper.findByItem(name,startDate,endDate,status));
        return pageInfo;
    }

    @Override
    public void add(ProductBean product) {
        mapper.add(product);
    }

    @Override
    public void updateStatus(int id, String productStatus) {
        mapper.updateStatus(id, productStatus);
    }

    @Override
    public void updatePrice(int id, int price) {
        mapper.updatePrice(id, price);
    }

}
